﻿using AppDesign.Models.ManageType;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace AppDesign.Models
{
    public class AppDesignDatabaseInitializer: DropCreateDatabaseIfModelChanges<AppDesignContext>
    {
        
        protected override void Seed(AppDesignContext context)
        {
            DomainTypes dt1 = new DomainTypes() { ObjName = "int" };
            DomainTypes dt2 = new DomainTypes() { ObjName = "string" };
            DomainTypes dt3 = new DomainTypes() { ObjName = "bool" };
            DomainTypes dt4 = new DomainTypes() { ObjName = "DateTime" };

            AppTypes at1 = new AppTypes() { ObjName = "Worker" };
            AppTypes at2 = new AppTypes() { ObjName = "Person" };
            AppTypes at3 = new AppTypes() { ObjName = "GrandFather" };
            AppTypes at4 = new AppTypes() { ObjName = "Father" };

     
            AppTypes at5 = new AppTypes() {ObjName = "Son" };



            

            AppRelation ar1 = new AppRelation() {UniqueId = System.Guid.NewGuid() ,AppTypesPar = at3, AppTypesChild = at4, PropertyName = "MyFather", RelationType = "one", AccMod = "Public" };
            AppRelation ar2 = new AppRelation() {UniqueId = System.Guid.NewGuid(), AppTypesPar = at4, AppTypesChild = at5, PropertyName = "MySon", RelationType = "one", AccMod = "Private" };




            context.Set<AppRelation>().Add(ar1);
            context.Set<AppRelation>().Add(ar2);

            

            AppLayout al1 = new AppLayout() { AppTypes = at5, LayoutName = "Layout 1", Html = "<div><h2>I belong to Son type</h2></div>" };
            context.Set<AppLayout>().Add(al1);
            context.SaveChanges();

            AppLayout al2 = new AppLayout() { AppTypes = at3, LayoutName = "Layout 2", Html = "<div><h2>I belong to Father type</h2>_getLayout(" + al1.UniqueId + ") </div>" };  
            context.Set<AppLayout>().Add(al2);
            context.SaveChanges();

            AppLayout al3 = new AppLayout() { AppTypes = at2, LayoutName = "Layout 2", Html = "<div><h2>I belong to Father type</h2>_getLayout(" + al2.UniqueId + ") </div>" };
            context.Set<AppLayout>().Add(al3);
            context.SaveChanges();

            AppLayout al4 = new AppLayout() { AppTypes = at4, LayoutName = "Layout 2", Html = "<div><h2>I belong to Father type</h2>_getLayout(" + al3.UniqueId + ") </div>" };
            context.Set<AppLayout>().Add(al4);
            context.SaveChanges();



            OutsideRelation r1 = new OutsideRelation() {UniqueId = System.Guid.NewGuid(), AppTypes = at1, DomainTypes = dt1, PropertyName = "Number", RelationType = "one", AccMod = "Public" };
            OutsideRelation r2 = new OutsideRelation() {UniqueId = System.Guid.NewGuid(), AppTypes = at1, DomainTypes = dt1, PropertyName = "Salary", RelationType = "one", AccMod = "Public" };
            OutsideRelation r3 = new OutsideRelation() {UniqueId = System.Guid.NewGuid(), AppTypes = at1, DomainTypes = dt2, PropertyName = "Address", RelationType = "one", AccMod = "Private" };
            OutsideRelation r4 = new OutsideRelation() {UniqueId = System.Guid.NewGuid(), AppTypes = at1, DomainTypes = dt2, PropertyName = "Description", RelationType = "one", AccMod = "Private" };

            OutsideRelation r5 = new OutsideRelation() {UniqueId = System.Guid.NewGuid(), AppTypes = at2, DomainTypes = dt1, PropertyName = "Age", RelationType = "one", AccMod = "Protected" };
            OutsideRelation r6 = new OutsideRelation() {UniqueId = System.Guid.NewGuid(), AppTypes = at2, DomainTypes = dt2, PropertyName = "Name", RelationType = "one", AccMod = "Protected" };
            OutsideRelation r7 = new OutsideRelation() {UniqueId = System.Guid.NewGuid(), AppTypes = at2, DomainTypes = dt3, PropertyName = "Gender", RelationType = "one", AccMod = "Private" };

            DomainTypes dt5 = new DomainTypes() { ObjName = "Company" };
            DomainTypes dt6 = new DomainTypes() { ObjName = "CEO" };
            OutsideRelation r8 = new OutsideRelation() {UniqueId = System.Guid.NewGuid(), AppTypes = at1, DomainTypes = dt5, PropertyName = "CtyTNHH", RelationType = "one", AccMod = "Private" };

            DomainRelation ir1 = new DomainRelation() {UniqueId = System.Guid.NewGuid(), DomainTypesPar = dt5, DomainTypesChild = dt2, PropertyName = "Founder", RelationType = "one", AccMod = "Private" };
            DomainRelation ir2 = new DomainRelation() {UniqueId = System.Guid.NewGuid(), DomainTypesPar = dt5, DomainTypesChild = dt4, PropertyName = "Birthday", RelationType = "one", AccMod = "Public" };
            DomainRelation ir3 = new DomainRelation() {UniqueId = System.Guid.NewGuid(), DomainTypesPar = dt6, DomainTypesChild = dt5, PropertyName = "IDTE", RelationType = "one", AccMod = "Private" };
            DomainRelation ir4 = new DomainRelation() {UniqueId = System.Guid.NewGuid(), DomainTypesPar = dt6, DomainTypesChild = dt3, PropertyName = "Rich", RelationType = "one", AccMod = "Protected" };

            context.Set<DomainRelation>().Add(ir1);
            context.Set<DomainRelation>().Add(ir2);
            context.Set<DomainRelation>().Add(ir3);
            context.Set<DomainRelation>().Add(ir4);

            context.Set<OutsideRelation>().Add(r1);
            context.Set<OutsideRelation>().Add(r2);
            context.Set<OutsideRelation>().Add(r3);
            context.Set<OutsideRelation>().Add(r4);
            context.Set<OutsideRelation>().Add(r5);
            context.Set<OutsideRelation>().Add(r6);
            context.Set<OutsideRelation>().Add(r7);
            context.Set<OutsideRelation>().Add(r8);

            context.Set<DomainTypes>().Add(dt1);
            context.Set<DomainTypes>().Add(dt2);

            context.SaveChanges();

        }
    }
}